home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / makelibrary.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  4KB  |  151 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: makelibrary.c,v 1.7 1996/10/24 15:50:52 aros Exp $
  4.     $Log: makelibrary.c,v $
  5.     Revision 1.7  1996/10/24 15:50:52  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.6  1996/10/23 14:28:54  aros
  9.     Use the respective macros to access and manipulate a libraries' jumptable
  10.  
  11.     Revision 1.5  1996/10/19 17:07:27  aros
  12.     Include <aros/machine.h> instead of machine.h
  13.  
  14.     Revision 1.4  1996/08/13 13:56:04  digulla
  15.     Replaced AROS_LA by AROS_LHA
  16.     Replaced some AROS_LH*I by AROS_LH*
  17.     Sorted and added includes
  18.  
  19.     Revision 1.3  1996/08/01 17:41:14  digulla
  20.     Added standard header for all files
  21.  
  22.     Desc:
  23.     Lang: english
  24. */
  25. #include <exec/execbase.h>
  26. #include <exec/memory.h>
  27. #include <dos/dos.h>
  28. #include <aros/asmcall.h>
  29.  
  30. /*****************************************************************************
  31.  
  32.     NAME */
  33.     #include <clib/exec_protos.h>
  34.  
  35.     AROS_LH5(struct Library *, MakeLibrary,
  36.  
  37. /*  SYNOPSIS */
  38.     AROS_LHA(APTR,       funcInit,   A0),
  39.     AROS_LHA(APTR,       structInit, A1),
  40.     AROS_LHA(ULONG_FUNC, libInit,    A2),
  41.     AROS_LHA(ULONG,      dataSize,   D0),
  42.     AROS_LHA(BPTR,       segList,    D1),
  43.  
  44. /*  LOCATION */
  45.     struct ExecBase *, SysBase, 14, Exec)
  46.  
  47. /*  FUNCTION
  48.     Allocates memory for the library, builds it and calls the library's
  49.     init vector. Generally this function is for internal use and for
  50.     use by library programmers that don't want to use the automatic
  51.     initialization procedure.
  52.  
  53.     INPUTS
  54.     funcInit   - Either a pointer to an array of function offsets
  55.              (starts with -1, relative to funcInit) or to an array
  56.              of absolute function pointers.
  57.     structInit - Pointer to a InitStruct() data region or NULL.
  58.     libInit    - The library's init vector or NULL.
  59.              The init vector is called with the library address (D0),
  60.              the segList (A0) and ExecBase (A6) as arguments.
  61.              If the init fails the init code has to free the base memory
  62.              and return NULL (the library address for success).
  63.     dataSize   - Size of the library structure including system structures.
  64.              Must be at least sizeof(struct Library).
  65.     segList    - BCPL pointer to the library segments. Used to free the
  66.              library later.
  67.  
  68.     RESULT
  69.     The library base address or NULL.
  70.  
  71.     NOTES
  72.     The library base is always aligned to the maximum of sizeof(LONG)
  73.     and double alignment restrictions.
  74.  
  75.     EXAMPLE
  76.  
  77.     BUGS
  78.  
  79.     SEE ALSO
  80.     AddLibrary(), RemLibrary(), MakeFunctions(), InitStruct(), SumLibrary().
  81.  
  82.     INTERNALS
  83.  
  84.     HISTORY
  85.  
  86. ******************************************************************************/
  87. {
  88.     AROS_LIBFUNC_INIT
  89.  
  90.     struct Library *library;
  91.     ULONG negsize=0;
  92.  
  93.     /* Calculate the jumptable's size */
  94.     if(*(WORD *)funcInit==-1)
  95.     {
  96.     /* Count offsets */
  97.     WORD *fp=(WORD *)funcInit+1;
  98.     while(*fp++!=-1)
  99.         negsize+=LIB_VECTSIZE;
  100.     }
  101.     else
  102.     {
  103.     /* Count function pointers */
  104.     void **fp=(void **)funcInit;
  105.     while(*fp++!=(void *)-1)
  106.         negsize+=LIB_VECTSIZE;
  107.     }
  108.  
  109.     /* Align library base */
  110.     negsize=AROS_ALIGN(negsize);
  111.  
  112.     /* Allocate memory */
  113.     library=(struct Library *)AllocMem(dataSize+negsize,MEMF_PUBLIC|MEMF_CLEAR);
  114.  
  115.     /* And initilize the library */
  116.     if(library!=NULL)
  117.     {
  118.     /* Get real library base */
  119.     library=(struct Library *)((char *)library+negsize);
  120.  
  121.     /* Build jumptable */
  122.     if(*(WORD *)funcInit==-1)
  123.         /* offsets */
  124.         MakeFunctions(library,(WORD *)funcInit+1,(WORD *)funcInit+1);
  125.     else
  126.         /* function pointers */
  127.         MakeFunctions(library,funcInit,NULL);
  128.  
  129.     /* Write sizes */
  130.     library->lib_NegSize=negsize;
  131.     library->lib_PosSize=dataSize;
  132.  
  133.     /* Create structure */
  134.     if(structInit!=NULL)
  135.         InitStruct(structInit,library,0);
  136.  
  137.     /* Call init vector */
  138.     if(libInit!=NULL)
  139.         library=AROS_UFC3(struct Library *, libInit,
  140.         AROS_UFCA(struct Library *,  library, D0),
  141.         AROS_UFCA(BPTR,              segList, A0),
  142.         AROS_UFCA(struct ExecBase *, SysBase, A6)
  143.         );
  144.     }
  145.     /* All done */
  146.     return library;
  147.  
  148.     AROS_LIBFUNC_EXIT
  149. } /* MakeLibrary */
  150.  
  151.